﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BlobTowerDefense.Tools;

namespace BlobTowerDefense.Pages.Controls
{
    public partial class ControlsSettings_Audio : UserControl
    {
        public ControlsSettings_Audio()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(ControlsSettings_Audio_Loaded);
        }

        void ControlsSettings_Audio_Loaded(object sender, RoutedEventArgs e)
        {
            Slider_VolumeMaster.Value = Loader.Load_MasterVolume_Current();
            Slider_VolumeMusic.Value = Loader.Load_MusicVolume_Current();
            Slider_VolumeSounds.Value = Loader.Load_SoundsVolume_Current();
        }

        private void Button_Mute_Click(object sender, RoutedEventArgs e)
        {
            if (Slider_VolumeMaster.Value != 0)
            {
                Slider_VolumeMaster.Value = 0;
                Slider_VolumeMusic.Value = 0;
                Slider_VolumeSounds.Value = 0;
            }
            else
            {
                Slider_VolumeMaster.Value = Loader.Load_MasterVolume_Previous();
                Slider_VolumeMusic.Value = Loader.Load_MusicVolume_Previous();
                Slider_VolumeSounds.Value = Loader.Load_SoundsVolume_Previous();
            }
        }

        private void Slider_VolumeMaster_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            Saver.Save_MasterVolume_Current((short)e.NewValue);
            Saver.Save_MasterVolume_Previous((short)e.OldValue);
        }

        private void Slider_VolumeMusic_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            Saver.Save_MusicVolume_Current((short)e.NewValue);
            Saver.Save_MusicVolume_Previous((short)e.OldValue);
        }

        private void Slider_VolumeSounds_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            Saver.Save_SoundsVolume_Current((short)e.NewValue);
            Saver.Save_SoundsVolume_Previous((short)e.OldValue);
        }
    }
}
